Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filter): setValue prop type #1888

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

viniciuslagedo
Copy link
Contributor

Summary

Resolves #1504

Examples

We have made a significant improvement in terms of consistency for those using the component. The types can be assumed based on props if you are using a multi- or single-value filter. So, if you pass a callback using an array of strings, it infers the value prop and the default value with the same type. Besides that, it is now possible to use custom handles on the setValue prop.

type Props = {
  onFilterChange: (value: string[]) => void
  filterValue: string[]
  defaultFilterValue: string[]
}

const MyFilter = (props: Props) => {
  const { onFilterChange, defaultFilterValue, filterValue } = props

  return (
    <Filter
        value={filterValue} // Based on setValue prop it infers the string[] type here
        setValue={onFilterChange} // No more type errors here
        label="Multiple status"
        defaultValue={defaultFilterValue} // Based on setValue prop it infers the string[] type here
      >
      <FilterItem value="Stable">Stable</FilterItem>
      <FilterItem value="Experimental">Experimental</FilterItem>
      <FilterItem value="Deprecated">Deprecated</FilterItem>
    </Filter>
  )
}

Change component to generic typed Value, defaulting to string. Infers type from value, setValue,
defaultValue.
We need to use the same behavior from filter provider here because of most part of props came from
it.
@viniciuslagedo viniciuslagedo requested a review from a team as a code owner August 26, 2024 18:24
Copy link

vercel bot commented Aug 26, 2024

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this project.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Filter: setValue prop
1 participant